package com.bhsy.hellobootspring;

import org.springframework.context.ApplicationContext;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContextAware;

public class SpringContextUtil implements ApplicationContextAware
{
    private static ApplicationContext applicationContext;
    public SpringContextUtil() {}

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
      {
        if (SpringContextUtil.applicationContext == null)
          {
            SpringContextUtil.applicationContext = applicationContext;
          }
      }
    public static ApplicationContext getApplicationContext()
      {
          return applicationContext;
      }
    public static Object getBean(String name)
      {
        return applicationContext.getBean(name);
      }
    public static Object getBean(Class<?> requiredType)
      {
        return applicationContext.getBean(requiredType);
      }
}
